ModalDialog((ModalFilterProcPtr) MyFilter, &itemNum);The compiler complained that it cannot covert my custom function to type RoutineDescriptor*, so I changed it by casting it to RoutineDescriptor:
ModalDialog((RoutineDescriptor*) MyFilter, &itemNum);There were no compile or link errors, but now, when I run the program, it crashes with a type 3 error.
What's the correct way to implement this?
A Create a UPP using NewRoutineDescriptor instead of casting to a UPP. In
Dialogs.h there is a macro for NewRoutineDescriptor called NewModalFilterProc.
Your code should look like this:
ModalFilterUPP myFilterUPP; myFilterUPP = NewModalFilterProc(MyFilter); ModalDialog(myFilterUPP, &itemNum);